package com.arpa.oms.domain.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.arpa.oms.domain.enums.OrderStatusEnum;
import com.arpa.oms.domain.enums.PurchaseTypeEnum;
import com.arpa.wms.domain.entity.BasicEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.Valid;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * OMS采购单
 * </p>
 *
 * @author LEO
 * @since 2020-10-22
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("oms_purchase")
@ApiModel(value = "OmsPurchase对象", description = "OMS采购单")
public class Purchase extends BasicEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "采购单号")
    @TableField("code")
    private String code;

    @ApiModelProperty(value = "来源单号",hidden = true)
    @TableField("source_code")
    private String sourceCode;

    @ApiModelProperty(value = "所属机构Code",hidden = true)
    @TableField("group_code")
    private String groupCode;

    @ApiModelProperty(value = "仓库",required = true)
    @TableField(value = "warehouse_code")
    @NotEmpty(message = "仓库不能为空" )
    private String warehouseCode;

    @ApiModelProperty(value = "货主标识",required = true)
    @NotEmpty(message = "货主不能为空" )
    @TableField("shipment_code")
    private String shipmentCode;

    @ApiModelProperty(value = "货主名称",required = true)
    @NotEmpty(message = "货主名称不能为空" )
    @TableField("shipment_name")
    private String shipmentName;

    @ApiModelProperty(value = "采购类型 NORMAL:普通采购",hidden = true)
    @TableField("purchase_type")
    private PurchaseTypeEnum purchaseType;


    @ApiModelProperty(value = "供应商标识",required = true)
    @NotEmpty(message = "供应商不能为空")
    @TableField("supplier_code")
    private String supplierCode;


    @ApiModelProperty(value = "计划到货日期")
    @TableField("gmt_plan_arrival")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate gmtPlanArrival;

    @ApiModelProperty(value = "计划采购数量（采购单位）",hidden = true)
    @TableField("plan_quantity")
    private BigDecimal planQuantity;

    @ApiModelProperty(value = "计划采购数量（基本单位）",hidden = true)
    @TableField("plan_basic_quantity")
    @Digits(integer = 14,fraction = 6)
    private BigDecimal planBasicQuantity;

    @ApiModelProperty(value = "实际采购数量（采购单位）",hidden = true)
    @TableField("actual_quantity")
    private BigDecimal actualQuantity;

    @ApiModelProperty(value = "实际采购数量（基本单位）",hidden = true)
    @TableField("actual_basic_quantity")
    private BigDecimal actualBasicQuantity;

    @ApiModelProperty(value = "付款金额")
    @Digits(integer = 14,fraction = 6)
    @TableField("payment_amount")
    private BigDecimal paymentAmount;

    @ApiModelProperty(value = "已使用付款金额，用于批次生成付款明细时，计算已使用的付款金额数量")
    @Digits(integer = 14,fraction = 6)
    @TableField("use_payment_amount")
    private BigDecimal usePaymentAmount;

    @ApiModelProperty(value = "欠款金额")
    @Digits(integer = 14,fraction = 6)
    @TableField("owed_amount")
    private BigDecimal owedAmount;

    @ApiModelProperty(value = "状态：新增、作废、待审核、审核通过、审核未通过",hidden = true)
    @TableField("status")
    private OrderStatusEnum status;

    @ApiModelProperty(value = "备注")
    @TableField("remarks")
    @Length(max = 100, message = "备注最多输入100个字符")
    private String remarks;

    @ApiModelProperty(value = "审核意见",hidden = true)
    @Length(max = 255, message = "审核意见最多输入255个字符")
    @TableField("verify_opinion")
    private String verifyOpinion;

    @ApiModelProperty(value = "审核人",hidden = true)
    @TableField("verify_by")
    private String verifyBy;

    @ApiModelProperty(value = "审核人姓名",hidden = true)
    @TableField("verify_name")
    private String verifyName;


    @ApiModelProperty(value = "退货数量（采购单位）",hidden = true)
    @TableField("refund_quantity")
    private BigDecimal refundQuantity;

    @ApiModelProperty(value = "退货数量（基本单位）",hidden = true)
    @TableField("refund_basic_quantity")
    private BigDecimal refundBasicQuantity;


    /**
     * 创建时间
     * 自动填充
     */
    @ApiModelProperty(hidden = true)
    @TableField(value = "gmt_verify")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime gmtVerify;

    @Valid
    @TableField(exist = false)
    private List<PurchaseItem> purchaseItemList;

}
